package com.olinsports.system.olinsportssystem.controller;

import com.olinsports.system.olinsportssystem.manager.CommodityDetailedManager;
import com.olinsports.system.olinsportssystem.manager.InventoryDetailsManager;
import com.olinsports.system.olinsportssystem.model.CommodityDetailed;
import com.olinsports.system.olinsportssystem.model.InventoryDetails;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/7/22.
 */
@Controller
@RequestMapping("inventoryDetails")
public class InventoryDetailsController {
    @Autowired
    private InventoryDetailsManager inventoryDetailsManager;


    @RequestMapping("/selectAll")
    @ResponseBody
    public List<InventoryDetails> selectAll(){
        return inventoryDetailsManager.selectAll();
    }
    @RequestMapping("/insertAll")
    @ResponseBody
    public int insertAll(InventoryDetails InventoryDetails){
        return inventoryDetailsManager.insertAll(InventoryDetails);
    }

    @RequestMapping("/deleteByKey")
    @ResponseBody
    public int deleteByKey(int detailedKey){
        return inventoryDetailsManager.deleteByKey(detailedKey);
    }
    @RequestMapping("/updateData")
    @ResponseBody
    public int updateData(InventoryDetails InventoryDetails){
        return inventoryDetailsManager.updateData(InventoryDetails);
    }

    @RequestMapping("/selectByKey")
    @ResponseBody
    public InventoryDetails selectByKey(int inventoryKey){
        return inventoryDetailsManager.selectByKey(inventoryKey);
    }

    @RequestMapping("/listOrSearchInvent")
    @ResponseBody
    public Map listOrSearchInvent(String page, String rows, boolean _search, String sord, String sidx){
        return inventoryDetailsManager.listOrSearchInvent(page,rows,_search,sord,sidx);
    }

    @RequestMapping("/saveInventoryDetails")
    @ResponseBody
    public int saveInventoryDetails(InventoryDetails InventoryDetails,int typekey,int detailsKey) {
        return inventoryDetailsManager.saveInventoryDetails(InventoryDetails,typekey,detailsKey);
    }

    @RequestMapping("/searchDate")
    @ResponseBody
    public Map searchDate(String page, String rows,String startDate,String endDate){
        System.out.println(startDate);
        return inventoryDetailsManager.searchDate(page,rows,startDate,endDate);
    }

    @RequestMapping(value = "/toDcExcel",method= RequestMethod.POST)
    public ModelAndView toDcExcel(String startDate,String endDate,HSSFWorkbook workbook)throws Exception{
        return inventoryDetailsManager.toDcExcel(startDate,endDate,workbook);
    }

    /*@RequestMapping(value = "/toExcelHttp",method= RequestMethod.POST)
    @ResponseBody
    public  List<InventoryDetails>  toExcelHttp(String startDate,String endDate){
        return inventoryDetailsManager.toExcelHttp(startDate,endDate);
    }*/

    @RequestMapping("/searchSelf")
    @ResponseBody
    public Map searchSelf(String page, String rows,String field,String fieldValue){
        System.out.println("field = "+field);
        return inventoryDetailsManager.searchSelf(page,rows,field,fieldValue);
    }
}
